<?php

class certificate_model extends \swap\rdb_model {
    
    const introduction_length = 500;
    
    public static function prop_rules($operation) {
        $rules = array(
            'new' => '',
            'edit' => '',
        );
        return $rules[$operation];
    }
    public static function type_rule() {
        $rule = array(
            'type' => array(
                'change_to' => 'int',
            ),
        );
        return $rule;
    }
    public static function name_rule() {
        $rule = array(
            'name' => array(
                'change_to' => 'int',
            ),
        );
        return $rule;
    }
    public static function time_rule() {
        $rule = array(
            'get_time' => array(
                'change_to' => 'string',
                'callback' => function(&$get_time) {
                    $get_time = strtotime($get_time);
                }
            ),
        );
        return $rule;
    }
    public static function introduction_rule() {
        $rule = array(
            'introduction' => array(
                'change_to' => 'string',
                'pass_if_be' => '',
                'char_size' => array(0, self::introduction_length, '最多可输入%d个字符'),
            ),
        );
        return $rule;
    }
    
    public static function get_certificates_by_resume_id($resume_id) {
        $certificates = self::get(array('resume_id' => $resume_id), array(array('id' => 'desc')));
        return $certificates;
    }
}